package com.zlzlib.liblayoutmanager;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * @Desc: 横向的工具
 * @Copyright:
 * @DateTime: 2021/8/12 15:39
 * @Author zlz
 * @Version 1.0
 */
public class OrientationHorizontalUtils extends OrientationUtils {

    protected OrientationHorizontalUtils(RecyclerView.LayoutManager mLayoutManager) {
        super(mLayoutManager);
    }

    @Override
    public int getDecoratedStart(View view) {
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        return mLayoutManager.getDecoratedLeft(view) - params.leftMargin;
    }

    @Override
    public int getDecoratedEnd(View view) {
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        return mLayoutManager.getDecoratedRight(view) + params.rightMargin;
    }

    @Override
    public int getTransformedEndWithDecoration(View view) {
        mLayoutManager.getTransformedBoundingBox(view, true, mTmpRect);
        return mTmpRect.right;
    }

    @Override
    public int getTransformedStartWithDecoration(View view) {
        mLayoutManager.getTransformedBoundingBox(view, true, mTmpRect);
        return mTmpRect.left;
    }

    @Override
    public int getDecoratedMeasurement(View view) {
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        return mLayoutManager.getDecoratedMeasuredWidth(view) + params.leftMargin + params.rightMargin;
    }

    @Override
    public int getDecoratedMeasurementInOther(View view) {
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        return mLayoutManager.getDecoratedMeasuredHeight(view) + params.topMargin + params.bottomMargin;
    }

    @Override
    public int getStartAfterPadding() {
        return mLayoutManager.getPaddingLeft();
    }

    @Override
    public int getEndAfterPadding() {
        return mLayoutManager.getWidth() - mLayoutManager.getPaddingRight();
    }

    @Override
    public int getEnd() {
        return mLayoutManager.getWidth();
    }

    @Override
    public int getEndPadding() {
        return mLayoutManager.getPaddingRight();
    }

    @Override
    public int getTotalSpace() {
        return mLayoutManager.getWidth() - mLayoutManager.getPaddingLeft() - mLayoutManager.getPaddingRight();
    }

    @Override
    public int getTotalSpaceInOther() {
        return mLayoutManager.getHeight() - mLayoutManager.getPaddingTop() - mLayoutManager.getPaddingBottom();
    }

    @Override
    public int getMode() {
        return mLayoutManager.getWidthMode();
    }

    @Override
    public int getModeInOther() {
        return mLayoutManager.getHeightMode();
    }
}
